package com.yzh.openai.domain.openai.service.rule.impl;

import com.yzh.openai.domain.openai.annotation.LogicStrategy;
import com.yzh.openai.domain.openai.model.aggregates.ChatProcessAggregate;
import com.yzh.openai.domain.openai.model.entity.RuleLogicEntity;
import com.yzh.openai.domain.openai.model.entity.UserAccountEntity;
import com.yzh.openai.domain.openai.model.valobj.LogicCheckTypeVO;
import com.yzh.openai.domain.openai.model.valobj.UserAccountStatusVO;
import com.yzh.openai.domain.openai.service.rule.ILogicFilter;
import com.yzh.openai.domain.openai.service.rule.factory.DefaultLogicFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutionException;

/**
 * 账户校验
 */
@Slf4j
@Component
@LogicStrategy(logicMode = DefaultLogicFactory.LogicModel.ACCOUNT_STATUS)
public class AccountStatusFilter implements ILogicFilter<UserAccountEntity> {

    @Override
    public RuleLogicEntity<ChatProcessAggregate> filter(ChatProcessAggregate chatProcess, UserAccountEntity data) throws ExecutionException {
        //账户可用，放行
        if (UserAccountStatusVO.AVAILABLE.equals(data.getStatus())) {
            return RuleLogicEntity.<ChatProcessAggregate>builder()
                    .type(LogicCheckTypeVO.SUCCESS)
                    .data(chatProcess)
                    .build();
        }
        return RuleLogicEntity.<ChatProcessAggregate>builder()
                .type(LogicCheckTypeVO.REFUSE)
                .info("您的账户已冻结，暂时不可使用。请联系客服处理")
                .build();
    }
}
